package de.clapp.club;

import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ListView;
import de.clapp.CLAppModel;
import de.clapp.R;
import de.clapp.data.Club;
import de.clapp.menucard.MenucardModel;

public class ClubListFragment extends ListFragment
{
    private ClubListAdapter adapter;
    @Override
    public void onResume()
    {
        super.onResume();
        adapter = new ClubListAdapter(getActivity(), this);
        setListAdapter(adapter);
        
        this.setListShown(false);
        ClublistModel.getInstance().addListener(adapter);
    }

    @Override
    public void onPause()
    {
        ClublistModel.getInstance().removeListener(adapter);
        adapter = null;
        super.onPause();
    }
    
    @Override
    public void onListItemClick(ListView l, View v, int position, long id)
    {
        super.onListItemClick(l, v, position, id);
        Club currentClub = ClublistModel.getInstance().getClubList().get(position);
        CLAppModel.getInstance().setCurrentClub(currentClub);
        MenucardModel.getInstance().flushData();
        System.out.println(currentClub.getName());
        MenucardModel.getInstance().loadData(getActivity());
        getActivity().getActionBar().setSelectedNavigationItem(1);
        CLAppModel.getInstance().getClubMainFragment().setCurrentFragment(R.id.action_club_menu);
    }
}